package com.edushare.common.mailer;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;

public class MailBase {
	public static void main(String[] args){
		System.out.println(get().getClass().getResource("Invite.template").getPath());
		System.out.println(get().stringMap.get(INVITE_MAIL));
	}
	
	public static MailBase get(){
		if(singleton == null){
			singleton = new MailBase();
		}
		return singleton;
	}
	
	public MailBase() {
		try{
	    	stringMap.put(INVITE_MAIL, readInputStream(getClass().getResourceAsStream("/mailTemplates/Invite.template")));
	    	stringMap.put(SCHEDULE_MAIL, readInputStream(getClass().getResourceAsStream("/mailTemplates/Schedule.template")));
	    	stringMap.put(REQUIRED_COURSES_MAIL, readInputStream(getClass().getResourceAsStream("/mailTemplates/MandatoryCourses.template")));
	    	stringMap.put(OPTIONAL_COURSES_MAIL, readInputStream(getClass().getResourceAsStream("/mailTemplates/ElectiveChooser.template")));
	    	stringMap.put(SCHCANCEL_MAIL, readInputStream(getClass().getResourceAsStream("/mailTemplates/SchCancel.template")));
	    	stringMap.put(MESSAGE_MAIL, readInputStream(getClass().getResourceAsStream("/mailTemplates/Message.template")));
	    	stringMap.put(NEWUSER_MAIL, readInputStream(getClass().getResourceAsStream("/mailTemplates/NewUser.template")));
	    	stringMap.put(NEW_ASSIGNMENT_MAIL, readInputStream(getClass().getResourceAsStream("/mailTemplates/NewAssignment.template")));
	    	stringMap.put(EDITED_ASSIGNMENT_MAIL, readInputStream(getClass().getResourceAsStream("/mailTemplates/EditAssignment.template")));
	    	stringMap.put(FILE_UPLOAD_MAIL, readInputStream(getClass().getResourceAsStream("/mailTemplates/FileUpload.template")));
	    	stringMap.put(DELETED_ASSIGNMENT_MAIL, readInputStream(getClass().getResourceAsStream("/mailTemplates/DeletedAssignment.template")));
	    	stringMap.put(EXISTING_INVITE_MAIL, readInputStream(getClass().getResourceAsStream("/mailTemplates/ExistingUserInvite.template")));
	    	stringMap.put(NEW_POLL_MAIL, readInputStream(getClass().getResourceAsStream("/mailTemplates/NewPoll.template")));
	    	stringMap.put(NEW_UNIV_REGISTRATION, readInputStream(getClass().getResourceAsStream("/mailTemplates/NewUnivRegistration.template")));
	    	stringMap.put(FACULTY_GRADE_UPDATE, readInputStream(getClass().getResourceAsStream("/mailTemplates/FacultyGradeUpdate.template")));
    	}catch(Exception e){
    		e.printStackTrace();
    	}		
	}
	
	public static String readInputStream(InputStream is) throws IOException{
		
		BufferedReader br = new BufferedReader(new InputStreamReader(is));
		String line;
		StringBuffer buff = new StringBuffer();
		while((line = br.readLine()) !=null){
			buff.append(line);
		}
		
		return buff.toString();
	}

    public final HashMap<Integer, String> stringMap = new HashMap<Integer, String>();
    	
	private static MailBase singleton = null;

	public static final Integer  INVITE_MAIL 				= 0;
	public static final Integer  SCHEDULE_MAIL				= 1;
	public static final Integer  REQUIRED_COURSES_MAIL  	= 2;
	public static final Integer  OPTIONAL_COURSES_MAIL		= 3;
	public static final Integer  SCHCANCEL_MAIL 			= 4;
	public static final Integer  MESSAGE_MAIL				= 5;
	public static final Integer  NEWUSER_MAIL				= 6;
	public static final Integer  NEW_ASSIGNMENT_MAIL 		= 7;
	public static final Integer  EDITED_ASSIGNMENT_MAIL     = 8;
	public static final Integer  FILE_UPLOAD_MAIL 			= 9;
	public static final Integer  DELETED_ASSIGNMENT_MAIL 	= 10;
	public static final Integer  EXISTING_INVITE_MAIL 		= 11;
	public static final Integer  NEW_POLL_MAIL 				= 12;
	public static final Integer  NEW_UNIV_REGISTRATION		= 13;
	public static final Integer  FACULTY_GRADE_UPDATE		= 14;
}
